import { useChatStore } from '@/stores/chat'
const chatStore = useChatStore()

// 节流函数，用于限制函数调用频率
export const throttle = (fn, delay) => {
  let lastTime = 0
  return function (...args) {
    const now = Date.now()
    if (now - lastTime >= delay) {
      fn.apply(this, args)
      lastTime = now
    }
  }
}

// 计算拖拽开始时的初始位置
export const calculateStartPosition = (e, currentPosition) => ({
  x: e.clientX/chatStore.zoomVal - currentPosition.x,
  y: e.clientY/chatStore.zoomVal - currentPosition.y
})

// 计算拖拽过程中的新位置
export const calculateNewPosition = (e, startPosition) => {
  let newX = e.clientX/chatStore.zoomVal - startPosition.x
  let newY = e.clientY/chatStore.zoomVal - startPosition.y
  if (newX < 0) newX = 0
  if (newY < 0) newY = 0
  const maxX = window.innerWidth/chatStore.zoomVal - 30
  const maxY = window.innerHeight/chatStore.zoomVal - 30
  if (newX > maxX) newX = maxX
  if (newY > maxY) newY = maxY
  return { x: newX, y: newY }
}


export const sessionParam = {
  openType: 'inline',
  iframeId: 'sessionIframe',
  resourceType: 'local',
  connectType: 'app',
  uiConfig: {
    toolbar: {
      visible: false,
      adminMenu: true, // 管理菜单
      perferenceSettingTab: true, // 偏好设置菜单
      displayTab: true, // 显示菜单
      graphicTab: true, // 画面菜单
      mouseControlTab: true, // 鼠标操控菜单
      uploadMenu: true, // 上传菜单
      downloadMenu: true, // 下载菜单
    },
  }
};